package product_controller

import (
	"gorm-demo/database"
	"gorm-demo/entity"
	"gorm-demo/util"

	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
)

func AddProduct(c *gin.Context) {
	var product entity.Product
	c.BindJSON(&product)
	id := uuid.New().String()
	product.CreateTime = util.GetCurrentTime()
	product.UpdateTime = util.GetCurrentTime()
	product.Id = id
	result := database.DB.Create(&product)
	if result.Error != nil {
		c.JSON(400, gin.H{
			"code":    "500",
			"message": "添加产品失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code":    "200",
		"message": "添加产品成功",
	})
}
